﻿
Imports xhtmlctrl

Public Class autowrap

    Public Const className As String = "wc_wr"

    Public Shared Sub setclass(ByVal control As xhtmlControl)
        assert(Not control Is Nothing, "control is nothing.")
        If isemptystring(control.class) Then
            control.class = className
        ElseIf Not containsClass(control, className) Then
            control.class += character.blank + className
        End If
    End Sub

    Public Shared Sub invoke(ByVal inlineStyle As inlineStyle, ByVal control As xhtmlControl)
        'assert(Not inlineStyle Is Nothing, "inlineStyle is nothing.")
        setclass(control)
        If Not inlineStyle Is Nothing Then
            inlineStyle.addstyle("autowrap", "." + className + "{white-space:pre-wrap;" + _
                                                                "white-space:-moz-pre-wrap;" + _
                                                                "white-space:-pre-wrap;" + _
                                                                "white-space:-o-pre-wrap;" + _
                                                                "word-wrap:break-word;}")
        End If
    End Sub

    Public Shared Sub invoke(ByVal page As xhtmlpage, ByVal control As xhtmlControl)
        'assert(Not page Is Nothing, "page is nothing.")
        If page Is Nothing Then
            invoke(CType(Nothing, inlineStyle), control)
        Else
            invoke(page.inlineStyle(), control)
        End If
    End Sub
End Class
